Rotating data for neural network computations

ABSTRACT

Methods, systems, and apparatus, including computer programs encoded on computer storage media, for computing a layer output for a convolutional neural network layer, the method comprising: receiving a plurality of activation inputs; forming a plurality of vector inputs from the plurality of activation inputs, each vector input comprising values from a distinct region within the multi-dimensional matrix; sending the plurality of vector inputs to one or more cells along a first dimension of the systolic array; generating a plurality of rotated kernel structures from each of the plurality of kernel; sending each kernel structure and each rotated kernel structure to one or more cells along a second dimension of the systolic array; causing the systolic array to generate an accumulated output based on the plurality of value inputs and the plurality of kernels; and generating the layer output from the accumulated output.

CROSS REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. application Ser. No.16/857,808, filed Apr. 24, 2020, which is a continuation of U.S.application Ser. No. 15/792,872, filed Oct. 25, 2017, which is acontinuation of U.S. application Ser. No. 14/845,022, filed Sep. 3,2015, which claims the benefit of U.S. Provisional Patent ApplicationNo. 62/164,998, filed on May 21, 2015, the entire contents of each arehereby incorporated by reference.

BACKGROUND

This specification relates to computing neural network inferences inhardware.

Neural networks are machine learning models that employ one or morelayers of models to generate an output, e.g., a classification, for areceived input. Some neural networks include one or more hidden layersin addition to an output layer. The output of each hidden layer is usedas input to the next layer in the network, i.e., the next hidden layeror the output layer of the network. Each layer of the network generatesan output from a received input in accordance with current values of arespective set of parameters.

Some neural networks include one or more convolutional neural networklayers. Each convolutional neural network layer has an associated set ofkernels. Each kernel includes values established by a neural networkmodel created by a user. In some implementations, kernels identifyparticular image contours, shapes, or colors. Kernels can be representedas a matrix structure of weight inputs. Each convolutional layer canalso process a set of activation inputs. The set of activation inputscan also be represented as a matrix structure.

Some existing systems perform computations for a given convolutionallayer in software. For example, the software can apply each kernel forthe layer to the set of activation inputs. That is, for each kernel, thesoftware can overlay the kernel, which can be representedmulti-dimensionally, over a first portion of activation inputs, whichcan be represented multi-dimensionally. The software can then compute adot product from the overlapped elements. The dot product can correspondto a single activation input, e.g., an activation input element that hasan upper-left position in the overlapped multi-dimensional space. Forexample, using a sliding window, the software then can shift the kernelto overlay a second portion of activation inputs and calculate anotherdot product corresponding to another activation input. The software canrepeatedly perform this process until each activation input has acorresponding dot product. In some implementations, the dot products areinput to an activation function, which generates activation values. Theactivation values can be combined, e.g., pooled, before being sent to asubsequent layer of the neural network.

One way of computing convolution calculations requires numerous matrixmultiplications in a large dimensional space. A processor can computematrix multiplications through a brute force method. For example,although compute-intensive and time-intensive, the processor canrepeatedly calculate individual sums and products for convolutioncalculations. The degree to which the processor parallelizescalculations is limited due to its architecture.

SUMMARY

In general, this specification describes a special-purpose hardwarecircuit that computes neural network inferences.

In general, one innovative aspect of the subject matter described inthis specification can be embodied in methods that include the actionsof computing a layer output for a convolutional neural network layerfrom a layer input for the convolutional neural network layer using atwo-dimensional systolic array, the convolutional neural network layerhaving a plurality of kernels, each kernel having a respective matrixstructure of weights, the method comprising: receiving a plurality ofactivation inputs, the plurality of activation inputs represented as amulti-dimensional matrix; forming a plurality of vector inputs from theplurality of activation inputs, each vector input comprising values froma distinct region within the multi-dimensional matrix; sending theplurality of vector inputs to one or more cells along a first dimensionof the systolic array; generating a plurality of rotated kernelstructures from each of the plurality of kernels, where generating aparticular rotated kernel structure comprises shifting elements in therespective matrix structure for the kernel along one dimension; sendingeach kernel structure and each rotated kernel structure to one or morecells along a second dimension of the systolic array; causing thesystolic array to generate an accumulated output based on the pluralityof value inputs and the plurality of kernels; and generating the layeroutput from the accumulated output.

Implementations can include one or more of the following features. Thefirst dimension of the systolic array corresponds to rows of thesystolic array, and where the second dimension of the systolic arraycorresponds to columns of the systolic array. Sending the plurality ofvector inputs to one or more cells comprises: sending, for a particularrow of the systolic array, a respective element from each vector inputto the particular row; and selecting, at each cell in the particularrow, one of the respective elements for storage in a register in thecell based on a multiplexor control signal. Sending the plurality ofvector inputs to one or more cells along a first dimension of thesystolic array comprises: sending each vector input to a distinct seriesof shift registers, each shift register shifting an element of thevector input to a subsequent shift register on a subsequent clock cycle,each shift register corresponding to a respective row in the systolicarray; and selecting, for each row, an output from the correspondingshift registers for use in the row. Forming a plurality of vector inputsfrom the plurality of activation inputs is based on a size of aparticular kernel structure, further comprising: overlapping theparticular kernel structure with the matrix representation of theplurality of activation inputs to form a first vector input fromelements in the matrix representation; forming one or more other vectorinputs from other elements that surround the overlapped particularkernel structure. Generating the layer output from the accumulatedoutput comprises normalizing and pooling the accumulated output togenerate the layer output. Sending the plurality of vector inputs to oneor more cells along a first dimension of the systolic array comprises:at a particular clock cycle, storing a first vector input in theplurality of vector inputs in a first cell of the systolic array; and ata subsequent clock cycle, shifting the first vector input in the firstcell to a second cell that is adjacent to the first cell and storing asecond vector input in the plurality of vector inputs in the first cell.

Particular embodiments of the subject matter described in thisspecification can be implemented so as to realize one or more of thefollowing advantages. Rotating activation inputs and weight inputs to aneural network processor can cause the hardware circuit to processinferences for neural networks having convolutional layers moreefficiently. In particular, multiple convolution calculations can beperformed in parallel. This allows a systolic array within the neuralnetwork process to be more fully utilized during each clock cycle.Rotations can also permit better usage of registers in processors, e.g.,CPUs and GPUs, which can improve performance. Rotations can also reducepower usage by reducing a number of cache fetches.

The details of one or more embodiments of the subject matter of thisspecification are set forth in the accompanying drawings and thedescription below. Other features, aspects, and advantages of thesubject matter will become apparent from the description, the drawings,and the claims.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 shows an example neural network having multiple layers.

FIG. 2 is a flow diagram of an example method for performing acomputation for a given layer of a neural network.

FIG. 3 shows an example neural network processing system.

FIG. 4 shows an example architecture including a matrix computationunit.

FIG. 5 shows an example architecture of a cell inside a systolic array.

FIG. 6 shows an example matrix structure having spatial dimensions and afeature dimension.

FIG. 7 shows an example illustration of how a kernel matrix structure issent to a systolic array.

FIG. 8 shows an example illustration of weight inputs inside cells afterthree clock cycles.

FIG. 9 is a flow diagram of an example method for computing a layeroutput for a convolutional neural network layer.

FIG. 10 is a flow diagram of an example method for performing acomputation for a given layer of a neural network using data rotations.

FIG. 11 is an example illustration of how rotated kernel matrixstructures are used to compute convolution calculations.

Like reference numbers and designations in the various drawings indicatelike elements.

DETAILED DESCRIPTION

A neural network having multiple layers can be used to computeinferences. For example, given an input, the neural network can computean inference for the input. The neural network computes this inferenceby processing the input through each of the layers of the neuralnetwork. In particular, the layers of the neural network are arranged ina sequence, each with a respective set of weights. Each layer receivesan input and processes the input in accordance with the set of weightsfor the layer to generate an output.

Therefore, in order to compute an inference from a received input, theneural network receives the input and processes it through each of theneural network layers in the sequence to generate the inference, withthe output from one neural network layer being provided as input to thenext neural network layer. Data inputs to a neural network layer, e.g.,either the input to the neural network or the outputs of the layer belowthe layer in the sequence, can be referred to as activation inputs tothe layer. Activation inputs can be represented as a matrix structure ofactivation values. This matrix structure is described further below inreference to FIG. 6 .

In some implementations, the layers of the neural network are arrangedin a directed graph. That is, any particular layer can receive multipleinputs, multiple outputs, or both. The layers of the neural network canalso be arranged such that an output of a layer can be sent back as aninput to a previous layer. In some implementations, at least one of thelayers of the neural network is a convolutional layer.

FIG. 1 shows an example neural network 100 having multiple layers. Eachlayer can process an input of a particular size and generate an outputof another size. By way of illustration, Layer 1 can process a 170×170×3image and output a 28×28×96 matrix of activation values. The 28×28×96matrix of activation values is processed by Layers 2-6, and the outputof Layer 6 can be used to generate an inference of the neural network.Layers 1-3 can be convolutional layers. These matrices will be describedfurther below in reference to FIG. 6 .

As described above, a convolutional neural network layer can have anassociated set of kernels. Each kernel includes a set of weight inputs,which when applied to activation inputs of the layer, can causeactivation values to be generated, which can be used to generate anoutput for the layer. In some implementations, applying weight inputs toactivation inputs includes performing a dot product of each weight inputwith a portion of activation inputs. Computing activation values, e.g.,the 28×28×96 matrix of activation values, for a convolutional layer isdescribed further below in reference to FIG. 7 .

FIG. 2 is a flow diagram of an example process 200 for performing acomputation for a given layer of a neural network using aspecial-purpose hardware circuit. For convenience, the method 200 willbe described with respect to a system having one or more circuits thatperforms the method 200. The process 200 can be performed for each layerof the neural network in order to compute an inference from a receivedinput.

The system receives sets of weight inputs (step 202) and sets ofactivation inputs (step 204) for the given layer. The sets of weightinputs and the sets of activation inputs can be received from dynamicmemory and a unified buffer, respectively, of the special-purposehardware circuit. In some implementations, both the sets of weightinputs and the sets of activation inputs can be received from theunified buffer.

The system generates accumulated values from the weight inputs and theactivation inputs using a matrix multiplication unit of thespecial-purpose hardware circuit (step 206). In some implementations,the accumulated values are dot products of the sets of weight inputs andthe sets of activation inputs. That is, for one set of weights, thesystem can multiply each weight input with each activation input and sumthe products together to form an accumulated value. The system can thencompute dot products of other set of weights with other sets ofactivation inputs. This will be described further below in reference toFIG. 7 .

The system can generate a layer output from the accumulation values(step 208) using a vector computation unit of the special-purposehardware circuit. In some implementations, the vector computation unitapplies an activation function to the accumulated values. The output ofthe layer can be stored in the unified buffer for use as an input to asubsequent layer in the neural network or can be used to determine theinference. The system finishes processing the neural network when areceived input has been processed through each layer of the neuralnetwork to generate the inference for the received input.

FIG. 3 shows an example special-purpose integrated circuit 300 forperforming neural network computations. The system 300 includes a hostinterface 302. The host interface 302 can receive instructions thatinclude parameters for a neural network computation. The parameters caninclude at least one or more of the following: how many layers should beprocessed, corresponding sets of weight inputs for each layer of thelayer, an initial set of activation inputs, i.e., the input to theneural network from which the inference is to be computed, correspondinginput and output sizes of each layer, a stride value for the neuralnetwork computation, and a type of layer to be processed, e.g., aconvolutional layer or a fully connected layer.

The host interface 302 can send the instructions to a sequencer 306,which converts the instructions into low level control signals thatcontrol the circuit to perform the neural network computations. In someimplementations, the control signals regulate dataflow in the circuit,e.g., how the sets of weight inputs and the sets of activation inputsflow through the circuit. The sequencer 306 can send the control signalsto a unified buffer 308, a matrix computation unit 312, and a vectorcomputation unit 314.

In some implementations, the sequencer 306 also sends control signals toa direct memory access engine 304 and dynamic memory 310. In someimplementations, the sequencer 306 is a processor that generates clockedsignals. The sequencer 306 can use timing of the clocked signals to, atappropriate times, send the control signals to each component of thecircuit 300. In some other implementations, the host interface 302passes in a clocked signal from an external processor.

The host interface 302 can send the sets of weight inputs and theinitial set of activation inputs to the direct memory access engine 304.The direct memory access engine 304 can store the sets of activationinputs at the unified buffer 308. In some implementations, the directmemory access stores the sets of weights to dynamic memory 310, whichcan be a memory unit. In some implementations, the dynamic memory islocated off of the circuit.

The unified buffer 308 is a memory buffer. It can be used to store theset of activation inputs from the direct memory access engine 304 andoutputs of the vector computation unit 314. The direct memory accessengine 304 can also read the outputs of the vector computation unit 314from the unified buffer 308.

The dynamic memory 310 and the unified buffer 308 can send the sets ofweight inputs and the sets of activation inputs, respectively, to thematrix computation unit 312. In some implementations, the matrixcomputation unit 312 is a two-dimensional systolic array. The matrixcomputation unit 312 can also be a one-dimensional systolic array orother circuitry that can perform mathematical operations, e.g.,multiplication and addition. In some implementations, the matrixcomputation unit 312 is a general purpose matrix processor. The matrixcomputation unit 312 will be described in more detail below withreference to FIG. 4 and FIG. 5 .

The matrix computation unit 312 can process the weight inputs and theactivation inputs and provide a vector of outputs to the vectorcomputation unit 314. In some implementations, the matrix computationunit sends the vector of outputs to the unified buffer 308, which sendsthe vector of outputs to the vector computation unit 314. The vectorcomputation unit can process the vector of outputs and store a vector ofprocessed outputs to the unified buffer 308. For example, the vectorcomputation unit 314 can apply a non-linear function to outputs of thematrix computation unit, e.g., a vector of accumulated values, togenerate activated values. In some implementations, the vectorcomputation unit 314 generates normalized values, pooled values, orboth. The vector of processed outputs can be used as activation inputsto the matrix computation unit 312, e.g., for use in a subsequent layerin the neural network.

FIG. 4 shows an example architecture 400 including a matrix computationunit. The matrix computation unit is a two-dimensional systolic array406. The array 406 includes multiple cells 404. In some implementations,a first dimension 420 of the systolic array 406 corresponds to columnsof cells and a second dimension 422 of the systolic array 406corresponds to rows of cells. The systolic array can have more rows thancolumns, more columns than rows, or an equal number of columns and rows.

In the illustrated example, value loaders 402 send activation inputs torows of the array 406 and a weight fetcher interface 408 sends weightinputs to columns of the array 406. In some other implementations,however, activation inputs are transferred to the columns and weightinputs are transferred to the rows of the array 406.

The value loaders 402 can receive the activation inputs from a unifiedbuffer, e.g., the unified buffer 308 of FIG. 3 . Each value loader cansend a corresponding activation input to a distinct left-most cell ofthe array 406. The left-most cell can be a cell along a left-most columnof the array 406. For example, value loader 412 can send an activationinput to cell 414. The value loader can also send the activation inputto an adjacent value loader, and the activation input can be used atanother left-most cell of the array 406. This allows activation inputsto be shifted for use in another particular cell of the array 406.

The weight fetcher interface 408 can receive the weight input from amemory unit, e.g., the dynamic memory 310 of FIG. 3 . The weight fetcherinterface 408 can send a corresponding weight input to a distincttop-most cell of the array 406. The top-most cell can be a cell along atop-most row of the array 406. For example, the weight fetcher interface408 can send weight inputs to cells 414 and 416.

In some implementations, a host interface, e.g., the host interface 302of FIG. 3 , shifts activation inputs throughout the array 406 along onedimension, e.g., to the right, while shifting weight inputs throughoutthe array 406 along another dimension, e.g., to the bottom. For example,over one clock cycle, the activation input at cell 414 can shift to anactivation register in cell 416, which is to the right of cell 414.Similarly, the weight input at cell 416 can shift to a weight registerat cell 418, which is below cell 414.

On each clock cycle, each cell can process a given weight input and agiven activation input to generate an accumulated output. Theaccumulated output can also be passed to an adjacent cell along the samedimension as the given weight input. An individual cell is describedfurther below with reference FIG. 5 .

The accumulated output can be passed along the same column as the weightinput, e.g., towards the bottom of the column in the array 406. In someimplementations, at the bottom of each column, the array 406 can includeaccumulator units 410 that store and accumulate each accumulated outputfrom each column when performing calculations with layers having moreweight inputs than columns or layers having more activation inputs thanrows. In some implementations, each accumulator unit stores multipleparallel accumulations. The accumulator units 410 can accumulate eachaccumulated output to generate a final accumulated value. The finalaccumulated value can be transferred to a vector computation unit, e.g.,the vector computation unit 214 of FIG. 2 . In some otherimplementations, the accumulator units 410 passes the accumulated valuesto the vector computation unit without performing any accumulations whenprocessing layers with fewer weight inputs than columns or layers havingfewer activating inputs than rows.

FIG. 5 shows an example architecture 500 of a cell inside a systolicarray, e.g., the systolic array 406 of FIG. 4 .

The cell can include an activation register 506 that stores anactivation input. The activation register can receive the activationinput from a left adjacent cell, i.e., an adjacent cell located to theleft of the given cell, or from a unified buffer, depending on theposition of the cell within the systolic array. The cell can include aweight register 502 that stores a weight input. The weight input can betransferred from a top adjacent cell or from a weight fetcher interface,depending on the position of the cell within the systolic array. Thecell can also include a sum in register 504. The sum in register 504 canstore an accumulated value from the top adjacent cell. Multiplicationcircuitry 508 can be used to multiply the weight input from the weightregister 502 with the activation input from the activation register 506.The multiplication circuitry 508 can output the product to summationcircuitry 510.

The summation circuitry can sum the product and the accumulated valuefrom the sum in register 504 to generate a new accumulated value. Thesummation circuitry 510 can then send the new accumulated value toanother sum in register located in a bottom adjacent cell. The newaccumulated value can be used as an operand for a summation in thebottom adjacent cell.

The cell can also shift the weight input and the activation input toadjacent cells for processing. For example, the weight register 502 cansend the weight input to another weight register in the bottom adjacentcell. The activation register 506 can send the activation input toanother activation register in the right adjacent cell. Both the weightinput and the activation input can therefore be reused by other cells inthe array at a subsequent clock cycle.

In some implementations, the cell also includes a control register. Thecontrol register can store a control signal that determines whether thecell should shift either the weight input or the activation input toadjacent cells. In some implementations, shifting the weight input orthe activation input takes one or more clock cycles. The control signalcan also determine whether the activation input or weight inputs aretransferred to the multiplication circuitry 508, or can determinewhether the multiplication circuitry 508 operates on the activation andweight inputs. The control signal can also be passed to one or moreadjacent cells, e.g., using a wire.

In some implementations, weights are pre-shifted into a weight pathregister 512. The weight path register 512 can receive the weight input,e.g., from a top adjacent cell, and transfer the weight input to theweight register 502 based on the control signal. The weight register 502can statically store the weight input such that as activation inputs aretransferred to the cell, e.g., through the activation register 506, overmultiple clock cycles, the weight input remains within the cell and isnot transferred to an adjacent cell. Therefore, the weight input can beapplied to multiple activation inputs, e.g., using the multiplicationcircuitry 508, and respective accumulated values can be transferred toan adjacent cell.

As described above, for a given neural network layer, the systolic arrayperforms the operations for the layer using two-dimensional matrixmultiplication.

In order to effectively perform convolution calculations using thesystolic array, the neural network processor parallelizes matrixmultiplications having large dimensional spaces, which are generallyrequired for convolution calculations. In particular, the neural networkprocessor can “flatten” matrices. By way of illustration, the neuralnetwork process can flatten a set of activation inputs. For example, theset of activation inputs can be represented as a 3D matrix. The 3Dmatrix can be visualized as a stack of 2D matrices. Each 2D matrix canthen be sent to a row of the systolic array. Kernels can then be sent tocolumns of the systolic array, and the systolic array can then use thekernels to perform numerous calculations on each 2D matrix at once,thereby parallelizing a convolution computation. This will be describedfurther below in reference to FIGS. 6-8 .

FIG. 6 shows an example matrix structure 600 having spatial dimensionsand a feature dimension. The matrix structure 600 can represent either aset of activation inputs or a set of weight inputs. A matrix structurefor a set of activation inputs will be referred to in this specificationas an activation matrix structure, and a matrix structure for a set ofweight inputs will be referred to in this specification as a kernelmatrix structure. The matrix structure 600 has three dimensions: twospatial dimensions and one feature dimension.

In some implementations, the spatial dimensions correspond to a space orposition of a set of activation inputs. For example, if the neuralnetwork is processing an image, which has two dimensions, the matrixstructures can have two spatial dimensions, which correspond to spatialcoordinates, i.e., XY coordinates, of the image.

The feature dimension corresponds to features from an activation input.Each feature dimension can have depth levels; for example, the matrixstructure 600 has depth levels 602, 604, and 606. By way ofillustration, if matrix structure 600 represents a 3×3×3 image sent as aset of activation inputs to a first layer, the X and Y dimensions of theimage (3×3) can be the spatial dimensions, and the Z dimension (3) canbe the feature dimension corresponding to R, G, and B values. That is,depth level 602 can correspond to a feature of nine ‘1’ activationinputs, e.g., red values, depth level 604 can correspond to a feature ofnine ‘2’ activation inputs, e.g., green values, and depth level 606 cancorrespond to a feature of nine ‘3’ activation inputs, e.g., bluevalues.

Although only three depth levels for the feature dimension areillustrated in the example of FIG. 6 , a given feature dimension canhave a large number, e.g., hundreds, of feature dimensions. Similarly,although only one feature dimension is illustrated, a given matrixstructure can have multiple feature dimensions.

In order to perform the computation for the convolutional layer, usingthe matrix structure 600, the system has to convert the convolutionalcomputation to a two-dimensional matrix multiplication.

FIG. 7 shows an example illustration of how a matrix structure 600 ofFIG. 6 is processed by a systolic array 706 at a given convolutionallayer. The matrix structure 600 can be a set of activation inputs.Generally, the neural network processor can send the activation inputs,e.g., elements within matrix structure 600, and weight inputs, e.g.,Kernels A-D 710, to rows and columns of the array, respectively. Theactivation and weight inputs can be shifted to the right and to thebottom, respectively, of the systolic array and must reach a particularposition, e.g., a particular register at a particular cell. Once theinputs are determined to be in place, e.g., via control signals, theprocessor can perform calculations using the inputs stored within thecells to generate the given layer's output.

The neural network processor “flattens” the matrix structure 600 beforesending portions of the structure 600 to rows of the systolic array, asdescribed above. That is, the neural network processor can split up thedepth layers 702 of the matrix structure 600, e.g., depth layers 602,604, and 606 of FIG. 6 , and send each depth layer to a distinct cell.In some implementations, each depth layer is sent to a cell on adifferent row of the systolic array 706. For example, the processor cansend the activation inputs from a first depth layer, e.g., a matrix ofnine ‘1’ activation inputs, to a left-most cell at a first row of thesystolic array 706, a second depth layer, e.g., a matrix of nine ‘2’activation inputs, to a left-most cell at a second row, a third depthlayer, e.g., a matrix of nine ‘3’ activation inputs, to a left-most cellat a third row, and so on.

The given layer can have multiple kernels, e.g., Kernels A-D 710.Kernels A-D 710 can have matrix structures of dimension 3×3×10. Theprocessor can send each kernel matrix structure to a cell at a distinctcolumn of the systolic array 706. For example, Kernel A can be sent to atop cell in a first column, Kernel B can be sent to a top cell in asecond column, and so on.

When a matrix structure is sent to a cell, a first element of the matrixcan be stored in the cell during one clock cycle. On the next clockcycle, a next element can be stored in the cell. The first elementstored can be shifted to an adjacent cell, as described above inreference to FIG. 5 . The shifting of inputs can continue until allelements of the matrix structure are stored in the systolic array 706.Both activation inputs and weight inputs can be shifted throughout eachcell after one or more clock cycles. Shifting of the inputs within thesystolic array will be described further below in reference to FIG. 8 .

In some implementations, the systolic array 706 has a large number ofrows and a large number of columns, e.g., 256 rows and 256 columns. If agiven layer of the neural network has a fewer sets of weight inputs thancolumns in the systolic array 706, the processor can replicate one ormore matrix structures for the sets of weight kernels and send thereplicated matrix structures to unused columns of the array 706. If thegiven layer has a fewer sets of activation inputs than columns in thearray, the processor can replicate one or more matrix structures for thesets of activation inputs and send the replicated matrix structures tounused rows of the array 706. By replicating sets of activation inputsor sets of weight inputs, or both, the processor can perform multipleconvolution calculations in parallel.

FIG. 8 shows an example illustration 800 of weight inputs inside cellsof an example 3×3 systolic array after three clock cycles. Each cell canstore a weight input and an activation input, as described above inreference to FIG. 5 . Weight inputs can be sent to cells at distinctcolumns of the systolic array for convolution calculations, as describedabove in reference to FIG. 7 . By way of illustration, the system sendsa first kernel matrix structure having weight inputs of 1, 2, and 4 to afirst column of the systolic array. The system sends a second kernelstructure having weight inputs of 3, 5, and 7 to a second column. Thesystem sends a third kernel structure having weights 6, 8, and 10 to athird column. After every clock cycle, weight inputs can be shifted inone dimension, e.g., from top to bottom, while activation inputs can beshifted (not illustrated) in another dimension, e.g., from left toright.

Weight inputs can be stored within cells in a staggered manner. That is,a state of the systolic array after a first clock cycle 802 shows a ‘1’inside a top-left cell. The ‘1’ represents the weight input of ‘1’stored in the cell. At the next clock cycle 804, the ‘1’ is shifted to acell under the top-left cell, and another weight input from the kernel,‘2’, is stored in the top-left cell as well as a weight input of ‘3’ ata top-most cell at a second column.

On a third clock cycle, 806, each weight is shifted again. In the firstcolumn, a bottom-most cell stores the ‘1’ weight input, the ‘2’ weightinput is stored where the ‘1’ weight input was stored on the previouscycle, and a ‘4’ weight input is stored in the top-left most cell.Similarly, in the second column, the ‘3’ is shifted down and a ‘5’weight input is stored in the top-middle cell. In the third column, a‘6’ weight input is stored in the top-right most cell.

In some implementations, a control signal for the weight inputs thatdetermines whether the weight inputs should be shifted is also shiftedalong with the weight inputs.

Activation inputs can be shifted in a similar fashion in the otherdimension, e.g., from left to right.

Once the activation inputs and the weight inputs are in place, theprocessor can perform a convolution calculation, e.g., by using themultiplication and summation circuitries within the cells, to generate aset of accumulated values to be used in a vector computation unit.

Although the system has been described with weight inputs being sent tocolumns of the array and activation inputs being sent to rows of thearray, in some implementations, the weight inputs are sent to rows ofthe array and the activation inputs are sent to columns of the array.

In some implementations, a neural network model has a stride parametergreater than one. The processor can perform computations with the strideparameter by converting matrix structures of activation input and weightinputs to respective permuted matrix structures having a larger featuredimension and smaller spatial dimensions.

In some implementations, when processing images, the processor permutes,i.e., remaps, the activation matrix structure to have the followingsize: CEIL(X/X_stride)×CEIL(Y/Y_stride)×(Sizeof(RGB)*X_stride*Y_stride),where X and Y are the size of the matrix structure dimensions, X_strideand Y_stride are the stride parameters, and Sizeof(RGB) is three. Thekernel matrix structure can also be permuted using the same formula. Forexample, if the stride parameter is 2×2, the activation matrix structureis originally 170×170×3 and the kernel matrix structure is 7×7×3, thepermuted activation matrix structure can be 85×85×12 and the permutedkernel matrix structure can be 4×4×12.

The coordinates of the activation and kernel matrix structures can bemapped to permuted coordinates using the following formula: [CEIL(X/2),CEIL(Y/2), Z+3*(X % 2)+6*(Y % 2)], where X, Y, and Z represent acoordinate in the respective matrix structure. Other formulas caninclude [CEIL(X/2), CEIL(Y/2), Z+3*(Y % 2)+6*(X % 2)] or [CEIL(X/2),CEIL(Y/2), 2*Z+(X % 2)+6*(Y % 2)].

FIG. 9 is a flow diagram of an example method for computing a layeroutput for a convolutional neural network layer. For convenience, themethod 900 will be described with respect to a system having one or morecircuits that performs the method 900, e.g., the circuit 300 of FIG. 3 .The process 900 can be performed for each convolutional layer of theneural network in order to compute an inference from a received input.

As described above, a convolutional neural network layer can have a setof kernels, and each kernel can be represented as a matrix structure ofweights.

The system can receive a layer input, e.g., data from an image, (step902). The layer input can be represented as a multi-dimensional matrixhaving multiple depth levels, as described above in matrix structure 600of FIG. 6 .

The system can send each kernel matrix structure to a distinct cellalong a first dimension of a systolic array within the system (step904). In some implementations, cells along the first dimension are cellslocated along columns of the array. For example, a given kernel matrixstructure can be converted to a vector of elements, and each element canbe shifted through a column of the systolic array as described above inreference to FIG. 8 .

The system can, for each depth level, send the respective matrix ofdistinct activation inputs to a distinct cell along a second dimensionof the systolic array (step 906). This is described above in referenceto FIG. 7 . In some implementations, the distinct cells along the seconddimension are cells located along rows of the array. Activation inputsat a particular depth level can be converted into a vector of elements,and each element can be shifted through a row of the systolic array asdescribed above in reference to FIG. 8 .

The system can cause the systolic array to generate an accumulatedoutput from the respective matrices sent to the cells (step 908), asdescribed above in reference to FIG. 4 .

The system can generate the layer output from the accumulated output(step 910), as described above in reference to FIGS. 3-4 .

Generally, data rotations is a concept of shifting data around to enablethe circuit to perform flattened convolutional calculations whilemaximizing utilization of the circuit. The circuit can rotate data, anexample of which will be described below in reference to FIG. 10 , anddirect dataflow of the rotated data to the systolic array such that dotproducts computed over the course of a few clock cycles generates a setof accumulated values that, for example, normally would take numerousmagnitudes of clock cycles to compute using a single-threaded processorarchitecture.

FIG. 10 is a flow diagram of an example method for performing acomputation for a given layer of a neural network using data rotations.For convenience, the method 1000 will be described with respect to asystem having one or more circuits that performs the method 1000.

The system receives a set of activation inputs and sets of weight inputs(step 1002). The activation and weight inputs can be received at atwo-dimensional systolic array from a unified buffer and a dynamicmemory unit, as described above in reference to FIG. 3 . The set ofactivation inputs and each set of weight inputs can be represented as amulti-dimensional matrix structure as described above in reference toFIG. 6 .

FIG. 11 is an example 1100 of how rotated kernel matrix structures areused to compute convolution calculations using a two-dimensionalsystolic array 1114. As shown in the example of FIG. 11 , the receivedset of activation inputs can be activation inputs 1102, i.e., a 5×5matrix of activation inputs, and an example set of weight inputs can bekernel structure 1104. For simplicity, the example 1100 illustrates howa convolution calculation can be performed at a first layer of a neuralnetwork using a two-dimensional image and a two-dimensional kernel. Thefirst layer can receive a 170×170 set of activation inputs, e.g., animage, and the first layer can have a kernel of weight inputsrepresented as a 3×3 kernel matrix structure 1104, i.e., a kernel with3×3 spatial dimensions. The example 1100 illustrates a two dimensionalweight rotation.

In some implementations, instead of receiving the set of activationinputs, the system determines the set of activation inputs by selectingthe set of activation inputs from a larger set of activation inputs. Theset of activation inputs, i.e., the 5×5 portion, can be selected basedon dimensions of the kernel to be applied to the set of activationinputs. For example, the system can choose to process the 170×170 imageby dividing the image into 5×5 portions, e.g., 5×5 activation inputs1102 because the 5×5 portion is used to calculate convolutions using a3×3 kernel structure.

In particular, when calculating convolutions, i.e., accumulated values,for a single element, the system overlays the kernel structure 1104 overthe set of activation inputs and computes a dot product using theoverlapped elements. For example, to compute a convolution for thetop-left most element 12, the system uses all elements inside quadrant1118. Similarly, to calculate convolutions for the bottom three andright most three elements in quadrant 1118, the 3×3 kernel matrixstructure 1104 overlaps with elements within a 5×5 portion of activationinputs 1102.

Returning to the description of FIG. 10 , the system forms sets ofvector inputs from the set of activation inputs (step 1004). The systemcan use dimensions of a kernel matrix structure, e.g., 3×3 kernelstructure 1104 of FIG. 11 , for the set of weight inputs to identify thesets of vector inputs. In particular, the system can overlap the kernelmatrix structure onto a portion of the activation inputs, e.g., 3×3kernel structure 1104 overlaps a quadrant 1108 of activation inputs1102.

Based on the overlapped portion, the system can divide the activationinputs 1102 into four quadrants, e.g., see axis 1120. In particular, thequadrants can be positioned over the activation inputs 1102 such that atleast one quadrant overlaps with the kernel matrix structure, e.g., thequadrant 1118 overlaps with a 3×3 kernel structure dimension, but theother three quadrants do not.

Elements from each quadrant can be used to form a vector input. By wayof illustration, activation inputs 1102 are divided into four sets ofvector inputs 1110: [12, 9, 11, 3, 1, 10, 11, 6, 6], [9, 2, 10, 0, 5,3], [12, 9, 6, 9, 15, 13], [7, 6, 12 2]. In some implementations, thevector inputs can be ordered by reading in the elements in a quadrant ina top-to-bottom, then left-to-right direction.

In some implementations, the elements can be padded, e.g., with 0's ifthe quadrant has fewer elements than a number of elements in the kernel.For example, a particular quadrant can have activation inputsrepresented in a 2×3 matrix:

$\quad{\begin{bmatrix}{12} & 6 & {15} \\9 & 9 & {13}\end{bmatrix}.}$The 2×3 matrix can be padded to match dimensions of kernel structure1104, i.e., a 3×3 matrix:

$\begin{bmatrix}{12} & 6 & {15} \\9 & 9 & {13} \\0 & 0 & 0\end{bmatrix}.$The circuit can then read the elements in a top-to-bottom, thenleft-to-right direction to form a set of vector inputs, e.g., see VectorInputs 1110 under the MUX value of 2: [12 9-6 9-15 13-].

In some implementations, instead of being divided into quadrants, theactivation inputs are divided into X regions, where X=2{circumflex over( )}n, and where n is the number of dimensions of the kernel matrixstructure. The system can then generate a set of vector inputs fromelements in each region.

Returning to the description of FIG. 10 , the system sends the sets ofvector inputs to one or more cells along a first dimension of thesystolic array, e.g., row cells (step 1006). In some implementations,the system first sends the sets of vector inputs to value loaders thatare adjacent to the systolic array, e.g., the value loaders described inreference to FIG. 4 . Each value loader can store multiple activationinputs and select one activation input to be sent to a cell along thefirst dimension based on a selector determined by the system, e.g., amultiplexor control signal. For example, if there are four sets ofvector inputs, a given value loader can store four activation inputs,i.e., one activation input from each set of vector inputs.

As shown in the example of FIG. 11 , the four sets of vector inputs1110: [12, 9, 11, 3, 1, 10, 11, 6, 6], [9, 2, 10, 0, 5, 3], [12, 9, 6,9, 15, 13], [7, 6, 12 2] can be sent to value loaders of the systolicarray 1114. Each value loader can include a multiplexor that receivesthe four vector inputs and a control signal.

Based on which activation input should be sent to the respective rowcell of the given value loader to complete the convolution calculation,the system can determine an appropriate multiplexor control signal,which can be generated by the neural network processor to cause thevalue loader to send the appropriate activation input to the respectiverow cell.

As an example, in FIG. 11 , the multiplexor control signal can determinewhich element of which vector is sent to the value loader'scorresponding row cell and thereby used in the current operation. Thecircuit, e.g., a host 202 of FIG. 2 , can select the multiplexor controlsignal based on what remaining products need to be computed for a givenconvolution calculation.

For example, for simplicity, consider activation input A and weightinput B. Since both activation inputs and weight inputs are loaded intothe systolic array 1114 in a staggered fashion, as described above withreference to FIG. 8 , when computing a product of A and B as part of aconvolution calculation, the system selects a multiplexor signal valuethat places A in the same cell as B at the particular clock cycle duringwhich the product will be computed. The system can select multiplexorsignal values, e.g., values 1116, to calculate convolutions for eachelement of each vector.

In some implementations, after one clock cycle, the activation inputs inthe value loader are shifted to an adjacent value loader thatcorresponds to an adjacent row. This allows the elements in the vectorinputs to shift to different rows of the systolic array, therebyexposing the elements for use in other rows. That is, if element 12 inthe vector formed by quadrant 1118 is not used in the first row by anycolumn, the element 12 can be shifted to an adjacent row on a subsequentclock cycle, and can be selected by a multiplexor signal for use in acell at a particular column in the systolic array. In someimplementations, shifting of elements of each vector input across valueloaders, thereby rotating the elements across rows, is referred to asvalue rotations.

In some implementations, the staggered loading of the activation inputs,e.g., over multiple clock cycles, based on multiplexor control signalsis referred to as temporally rotating the activation inputs.

Returning to the description of FIG. 10 , the system generates rotatedkernel matrix structures for each set of weight inputs (step 1008). Eachset of weight inputs is represented as a kernel matrix structure. Akernel matrix structure can be rotated by shifting elements in thekernel matrix structure along one dimension. For example, the dimensioncan be in the X-dimension, the Y-dimension, or the Z-dimension.

For example, in the example of FIG. 11 , the neural network processorcan generate rotated kernels 1108 from the kernel 1104. This can bereferred to as spatially rotating the given kernel. For example, theprocessor can shift elements of the kernel structure along either anX-dimension or a Y-dimension. That is, elements of kernel structure 1104

$\quad\begin{bmatrix}0 & 3 & 6 \\1 & 4 & 7 \\2 & 5 & 8\end{bmatrix}$

can be shifted left or right and top or bottom to generate eight rotatedkernel structures 1108 for a total of nine kernel structures. If thekernel structure had a size of 4×4, the processor can generate 16rotations, i.e., 4*4. If the kernel structure had a size of 3×3×3, theprocessor can generate 27 rotations, i.e., 3*3*3.

In some implementations, the processor uses stride in value rotations byvarying how fast activation inputs move down rows of the array. Forexample, activation inputs can be shifted more than one row per clockcycle.

In some implementations, the processor generates partial data rotations.That is, instead of generating all possible rotations, the processorgenerates some of the possible rotations for use on a first pass of thearray and a remainder of the possible rotations for use on a subsequentpass of the array. For example, instead of generating eight rotatedkernel structures 1108, the processor generates four for use on a firstpass and another four for use on a second pass. The processor cangenerate some of the possible rotations in situations where there aremore possible rotations than unused columns of the array.

Returning to the description of FIG. 10 , the system sends each kernelmatrix structure, rotated and un-rotated, to cells along a seconddimension of the systolic array, e.g., column cells (step 1010). In FIG.11 , the kernel structure 1104 and each rotated kernel structure can besent to distinct column cells of the systolic array 1114. Each row ofnumbers under a column represent a multiplexor (MUX) control signal, anactivation input (A), and a weight input (W). The numbers for theactivation input and the weight input can represent values stored withinregisters of a cell in the systolic array 1114.

By way of illustration, a total of nine kernel structures are sent tonine different columns of the systolic array 1114. Each kernel structurehas nine weight input elements, which are stored in nine rows of thesystolic array, e.g., in a staggered fashion as described in referenceto FIG. 8 . Activation input elements from the sets of vector inputs1110 are stored in particular cells based on the control signaldelivered to the MUX. The control signals can be preprogrammed into theneural network processor. For example, the first row of Column 0 has aMUX value of 0. Therefore, the systolic array 1114 can select a valuefrom the vector inputs 1110 corresponding to the first row and the MUXvalue of 0, i.e., the first element from vector input [12, 9, 11, 3, 1,10, 11, 6, 6]. The first row of Column 1 has a MUX value of 1.Therefore, the systolic array 1114 can select a value from the vectorinputs 1110 corresponding to the first row and the MUX value of 1, i.e.,the first element from vector input [9, 2, 10, 0, 5, 3].

Returning to the description of FIG. 10 , the system generatesaccumulated outputs from the systolic array (step 1012). In someimplementations, the systolic array computes a dot product of the weightand activation inputs stored in its cells. In the example of FIG. 11 ,when both the activation inputs and weight inputs are stored in theappropriate cells, e.g., made possible by the MUX signals, the systolicarray 1114 performs a dot product of the activation and weight inputs ona per column basis to generate accumulated values 1112, e.g., usingmultiplication and summation circuitry within cells of the systolicarray. The accumulated values 1112 can form an output 1106, which can besent to a vector computation unit, which is described above in referenceto FIG. 2 .

For example, for Column 0, the systolic array 1114 can perform a dotproduct using the kernel

$\quad\begin{bmatrix}0 & 3 & 6 \\1 & 4 & 7 \\2 & 5 & 8\end{bmatrix}$and the activation input from vector [12, 9, 11, 3, 1, 10, 11, 6, 6].Other sets of vector inputs are not used in Column 0 because thecorresponding MUX value is 0. Therefore, the systolic array computes anaccumulated value of 250 for column 0 by performing a dot product, i.e.,12*0+9*1+11*2+3*3+1*4+10*5+11*6+6*7+6*8=250.

Returning to the description of FIG. 10 , the system generates a layeroutput from the accumulated outputs (step 1014). The accumulated outputscan be sent to a vector computation unit, e.g., the vector computationunit described in reference to FIG. 3 . The vector computation unit canprocess the accumulated outputs and generate the layer output, e.g., asdescribed above in reference to FIG. 2 . The layer output can be sentand stored at the unified buffer.

The systolic array continues the convolution calculations over theentire set of activation inputs, i.e., the entire 170×170 image. In someimplementations, the convolution calculations are performed in apseudo-rasterized order. That is, because convolution calculations areperformed in parallel, performing convolution calculations in a normalraster order can cause convolution calculations to be repeated, whichwould be inefficient. Instead, the neural network processor can proceedin an order from left to right, top to down order that skips convolutioncalculations that have already been performed in previous parallelconvolution calculations. In effect, the processor can output chunks ata time, as opposed to single outputs in a normal raster order.

In some implementations, a subset of the rotated kernel structures aregenerated and a subset of vector inputs are sent to the systolic arrayif there are not enough unused columns or rows, respectively. Theremaining rotated kernel structures and remaining vector inputs can besent to the systolic array on a subsequent pass. In someimplementations, the rotated kernel structures, the vector inputs, orboth, are replicated for use in other unused columns of the systolicarray 1114 similarly described above in reference to FIG. 7 . That is,the kernel structures and the vector inputs can be replicated and sentto unused columns and rows, respectively, of the systolic array forcalculations to be performed in parallel.

Embodiments of the subject matter and the functional operationsdescribed in this specification can be implemented in digital electroniccircuitry, in tangibly-embodied computer software or firmware, incomputer hardware, including the structures disclosed in thisspecification and their structural equivalents, or in combinations ofone or more of them. Embodiments of the subject matter described in thisspecification can be implemented as one or more computer programs, i.e.,one or more modules of computer program instructions encoded on atangible non transitory program carrier for execution by, or to controlthe operation of, data processing apparatus. Alternatively or inaddition, the program instructions can be encoded on an artificiallygenerated propagated signal, e.g., a machine-generated electrical,optical, or electromagnetic signal, that is generated to encodeinformation for transmission to suitable receiver apparatus forexecution by a data processing apparatus. The computer storage mediumcan be a machine-readable storage device, a machine-readable storagesubstrate, a random or serial access memory device, or a combination ofone or more of them.

The term “data processing apparatus” encompasses all kinds of apparatus,devices, and machines for processing data, including by way of example aprogrammable processor, a computer, or multiple processors or computers.The apparatus can include special purpose logic circuitry, e.g., an FPGA(field programmable gate array) or an ASIC (application specificintegrated circuit). The apparatus can also include, in addition tohardware, code that creates an execution environment for the computerprogram in question, e.g., code that constitutes processor firmware, aprotocol stack, a database management system, an operating system, or acombination of one or more of them.

A computer program (which may also be referred to or described as aprogram, software, a software application, a module, a software module,a script, or code) can be written in any form of programming language,including compiled or interpreted languages, or declarative orprocedural languages, and it can be deployed in any form, including as astandalone program or as a module, component, subroutine, or other unitsuitable for use in a computing environment. A computer program may, butneed not, correspond to a file in a file system. A program can be storedin a portion of a file that holds other programs or data, e.g., one ormore scripts stored in a markup language document, in a single filededicated to the program in question, or in multiple coordinated files,e.g., files that store one or more modules, sub programs, or portions ofcode. A computer program can be deployed to be executed on one computeror on multiple computers that are located at one site or distributedacross multiple sites and interconnected by a communication network.

The processes and logic flows described in this specification can beperformed by one or more programmable computers executing one or morecomputer programs to perform functions by operating on input data andgenerating output. The processes and logic flows can also be performedby, and apparatus can also be implemented as, special purpose logiccircuitry, e.g., an FPGA (field programmable gate array) or an ASIC(application specific integrated circuit).

Computers suitable for the execution of a computer program include, byway of example, can be based on general or special purposemicroprocessors or both, or any other kind of central processing unit.Generally, a central processing unit will receive instructions and datafrom a read only memory or a random access memory or both. The essentialelements of a computer are a central processing unit for performing orexecuting instructions and one or more memory devices for storinginstructions and data. Generally, a computer will also include, or beoperatively coupled to receive data from or transfer data to, or both,one or more mass storage devices for storing data, e.g., magnetic,magneto optical disks, or optical disks. However, a computer need nothave such devices. Moreover, a computer can be embedded in anotherdevice, e.g., a mobile telephone, a personal digital assistant (PDA), amobile audio or video player, a game console, a Global PositioningSystem (GPS) receiver, or a portable storage device, e.g., a universalserial bus (USB) flash drive, to name just a few.

Computer readable media suitable for storing computer programinstructions and data include all forms of nonvolatile memory, media andmemory devices, including by way of example semiconductor memorydevices, e.g., EPROM, EEPROM, and flash memory devices; magnetic disks,e.g., internal hard disks or removable disks; magneto optical disks; andCD ROM and DVD-ROM disks. The processor and the memory can besupplemented by, or incorporated in, special purpose logic circuitry.

To send for interaction with a user, embodiments of the subject matterdescribed in this specification can be implemented on a computer havinga display device, e.g., a CRT (cathode ray tube) or LCD (liquid crystaldisplay) monitor, for displaying information to the user and a keyboardand a pointing device, e.g., a mouse or a trackball, by which the usercan send input to the computer. Other kinds of devices can be used tosend for interaction with a user as well; for example, feedback providedto the user can be any form of sensory feedback, e.g., visual feedback,auditory feedback, or tactile feedback; and input from the user can bereceived in any form, including acoustic, speech, or tactile input. Inaddition, a computer can interact with a user by sending documents toand receiving documents from a device that is used by the user; forexample, by sending web pages to a web browser on a user's client devicein response to requests received from the web browser.

Embodiments of the subject matter described in this specification can beimplemented in a computing system that includes a back end component,e.g., as a data server, or that includes a middleware component, e.g.,an application server, or that includes a front end component, e.g., aclient computer having a graphical user interface or a Web browserthrough which a user can interact with an implementation of the subjectmatter described in this specification, or any combination of one ormore such back end, middleware, or front end components. The componentsof the system can be interconnected by any form or medium of digitaldata communication, e.g., a communication network. Examples ofcommunication networks include a local area network (“LAN”) and a widearea network (“WAN”), e.g., the Internet.

The computing system can include clients and servers. A client andserver are generally remote from each other and typically interactthrough a communication network. The relationship of client and serverarises by virtue of computer programs running on the respectivecomputers and having a client-server relationship to each other.

While this specification contains many specific implementation details,these should not be construed as limitations on the scope of anyinvention or of what may be claimed, but rather as descriptions offeatures that may be specific to particular embodiments of particularinventions. Certain features that are described in this specification inthe context of separate embodiments can also be implemented incombination in a single embodiment. Conversely, various features thatare described in the context of a single embodiment can also beimplemented in multiple embodiments separately or in any suitablesubcombination. Moreover, although features may be described above asacting in certain combinations and even initially claimed as such, oneor more features from a claimed combination can in some cases be excisedfrom the combination, and the claimed combination may be directed to asubcombination or variation of a subcombination.

Similarly, while operations are depicted in the drawings in a particularorder, this should not be understood as requiring that such operationsbe performed in the particular order shown or in sequential order, orthat all illustrated operations be performed, to achieve desirableresults. In certain circumstances, multitasking and parallel processingmay be advantageous. Moreover, the separation of various system modulesand components in the embodiments described above should not beunderstood as requiring such separation in all embodiments, and itshould be understood that the described program components and systemscan generally be integrated together in a single software product orpackaged into multiple software products.

Particular embodiments of the subject matter have been described. Otherembodiments are within the scope of the following claims. For example,the actions recited in the claims can be performed in a different orderand still achieve desirable results. As one example, the processesdepicted in the accompanying figures do not necessarily require theparticular order shown, or sequential order, to achieve desirableresults. In certain implementations, multitasking and parallelprocessing may be advantageous.

What is claimed is:
 1. A method for performing computations for a layerof a neural network using a hardware array of compute cells in ahardware integrated circuit configured to implement the neural network,the method comprising: receiving an input data that flows through thehardware integrated circuit along a particular dimension of the hardwarearray of compute cells; obtaining a multi-dimensional matrix structurecomprising operands of the input data by reading the operands from amemory of the integrated circuit; and performing a convolution betweenoperands of the multi-dimensional matrix structure and a kernel for theneural network layer, comprising: rotating the multi-dimensional matrixstructure across a first dimension of the hardware array; andperforming, by the hardware array, the convolution using operands fromthe rotated multi-dimensional matrix structure and the kernel for theneural network layer.
 2. The method of claim 1, wherein the hardwarearray comprises an array of multiplication circuits and performing theconvolution comprises: performing, by the array of multiplicationcircuits, multiplication operations between operands of themulti-dimensional matrix structure and a weight input of the kernel. 3.The method of claim 1, wherein: the multi-dimensional matrix structureis a matrix structure of activation inputs; and the kernel is one of aplurality of kernels, each of the plurality of kernels being a matrixstructure of weight inputs for one or more layers of the neural network.4. The method of claim 3, further comprising: converting the matrixstructure of activation inputs to a first permuted matrix structure; andconverting at least one matrix structure of weight inputs to a secondpermuted matrix structure.
 5. The method of claim 1, wherein performing,by the hardware array, the convolution using operands from the rotatedmulti-dimensional matrix structure and the kernel for the neural networklayer produces a plurality of accumulation values, wherein the methodcomprises applying an activation function to the plurality ofaccumulated values to produce a layer output.
 6. The method of claim 5,comprising storing the layer output in a buffer as an input to asubsequent layer in the neural network.
 7. The method of claim 1,comprising receiving instructions at a host interface, wherein theinstructions comprise one or more of a number of layers of the neuralnetwork to process, corresponding input and output sizes for each layerof the neural network, a stride value, and a type of layer to beprocessed.
 8. The method of claim 7, comprising sending the instructionsto a sequencer, wherein the sequencer converts the instructions intocontrol signals.
 9. The method of claim 8, comprising sending at leastone control signal from the sequencer to a direct memory access engine.10. The method of claim 8, comprising generating, by the sequencer,clocked signals.
 11. The method of claim 1, wherein rotating themulti-dimensional matrix structure comprises shifting a first set ofoperands in a first value loader to a second value loader.
 12. Themethod of claim 11, wherein shifting occurs after a single clock cycle.13. The method of claim 1, comprising rotating the kernel.
 14. Themethod of claim 13, wherein performing the convolution comprisesperforming the convolution using the operands from the rotatedmulti-dimensional matrix structure and weights from the rotated kernel.15. The method of claim 13, wherein performing the convolution comprisesperforming the convolution using the operands from the rotatedmulti-dimensional matrix structure and a subset of the rotated kernel.